--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.
--Data Schema For Version 0.0.0.0
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_CategoryDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_CategoryDelete]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_CategoryDelete]
(
	@Original_CategoryID Int
)
AS
SET NOCOUNT OFF;

DELETE FROM 
	[Categories] 
WHERE 
	[CategoryID] = @Original_CategoryID ;

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_CategorySelectByCategoryPks]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_CategorySelectByCategoryPks]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE [dbo].[gen_CategorySelectByCategoryPks]
(
	@xml ntext
)
AS

DECLARE @hDoc int
EXEC sp_xml_preparedocument @hDoc OUTPUT, @xml

SELECT
		[Categories].[categoryname],
	[Categories].[categoryid],
	[Categories].[picture],
	[Categories].[description],
	[Categories].[created_by],
	[Categories].[created_date],
	[Categories].[modified_by],
	[Categories].[modified_date],
	[Categories].[time_stamp]

FROM 
[Categories]
WHERE

	[Categories].[CategoryID] IN (SELECT [CategoryID] 
											FROM OpenXML(@hDoc, '//Categories', 2) 
											WITH ([CategoryID] char(36) 'CategoryID')) 


exec sp_xml_removeDocument @hDoc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_CategorySelectByCategorySinglePk]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_CategorySelectByCategorySinglePk]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_CategorySelectByCategorySinglePk]
(
	@CategoryID Int
)
AS

SELECT 
	[Categories].[categoryname],
	[Categories].[categoryid],
	[Categories].[picture],
	[Categories].[description],
	[Categories].[created_by],
	[Categories].[created_date],
	[Categories].[modified_by],
	[Categories].[modified_date],
	[Categories].[time_stamp]

FROM
[Categories]
WHERE 
[Categories].[CategoryID] = @CategoryID 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_CategoryInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_CategoryInsert]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[gen_CategoryInsert]
(
	@CategoryName NVarChar(15) = default,
	@CategoryID Int = default,
	@Picture Image = default,
	@Description NText = default,
	@created_date datetime,
	@created_by varchar (50),
	@modified_by varchar (50)

)
AS
SET NOCOUNT OFF;

if (@created_date IS NULL)
SET @created_date = GetDate()
IF (@CategoryID < 0) SET @CategoryID = NULL;
if ((@CategoryID IS NULL))
BEGIN

INSERT INTO [Categories]
(
[CategoryName],
[Description],
[Picture],
[created_date],
[created_by],
[modified_date],
[modified_by]

)
VALUES
(
	@CategoryName,
	@Description,
	@Picture,
	@created_date,
	@created_by,
	@created_date,
	@modified_by

);

END
ELSE
BEGIN
SET identity_insert [Categories] on
INSERT INTO [Categories]
(
[CategoryID],
[CategoryName],
[Description],
[Picture],
[created_date],
[created_by],
[modified_date],
[modified_by]

)
VALUES
(
	@CategoryID,
	@CategoryName,
	@Description,
	@Picture,
	@created_date,
	@created_by,
	@created_date,
	@modified_by

);
SET identity_insert [Categories] off
END


SELECT 
	[Categories].[categoryname],
	[Categories].[categoryid],
	[Categories].[picture],
	[Categories].[description],
	[Categories].[created_by],
	[Categories].[created_date],
	[Categories].[modified_by],
	[Categories].[modified_date],
	[Categories].[time_stamp]

FROM
[Categories]
WHERE
	[Categories].[CategoryID] = SCOPE_IDENTITY();
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_CategoryPagingSelect]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_CategoryPagingSelect]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_CategoryPagingSelect]
(
	@page int, -- page number selected by the user
	@pageSize int, -- number of items on the page
	@orderByColumn varchar(100), -- name of column to order things by
	@ascending bit, -- order column ascending or descending
	@filter varchar(100) = null, -- filter statement passed in to determine like criteria on order by column
	@count int out -- number of items in the collection
)
AS

SET NOCOUNT ON;


CREATE TABLE #tmpTable
(
[CategoryID] Int
)

DECLARE @total__ivqatedr int
DECLARE @orderByColumnIndex int
-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@pageSize * @page)
IF (@total__ivqatedr <> 0)
BEGIN
	SET ROWCOUNT @total__ivqatedr
END
INSERT INTO #tmpTable
(
	[categoryid]
)
SELECT
	[Categories].[categoryid]
FROM
[Categories]
WHERE
	(@orderByColumn = 'CategoryName' and (((@filter is null) or ([Categories].[CategoryName] is null)) or (@filter is not null and [Categories].[CategoryName] LIKE @filter)))
or
	(@orderByColumn = 'CategoryID' and (((@filter is null) or ([Categories].[CategoryID] is null)) or (@filter is not null and [Categories].[CategoryID] = @filter)))
ORDER BY
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'CategoryName' THEN [Categories].[CategoryName] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'CategoryName' THEN [Categories].[CategoryName] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'CategoryID' THEN [Categories].[CategoryID] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'CategoryID' THEN [Categories].[CategoryID] END END

-- set @count based on the rows moved in the previous statement
SET ROWCOUNT 0
SET @count = (
SELECT count(*)
FROM
[Categories]
WHERE
	(@orderByColumn = 'CategoryName' and (((@filter is null) or ([Categories].[CategoryName] is null)) or (@filter is not null and [Categories].[CategoryName] LIKE @filter)))
or
	(@orderByColumn = 'CategoryID' and (((@filter is null) or ([Categories].[CategoryID] is null)) or (@filter is not null and [Categories].[CategoryID] = @filter)))
)

-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@pageSize * @page) - @pageSize
IF (@total__ivqatedr <> 0)
BEGIN
	SET ROWCOUNT @total__ivqatedr
	DELETE FROM #tmpTable
END

-- return the number of rows requested as the page size
SET ROWCOUNT @pageSize
SELECT
	[Categories].[categoryname],
	[Categories].[categoryid],
	[Categories].[picture],
	[Categories].[description],
	[Categories].[created_by],
	[Categories].[created_date],
	[Categories].[modified_by],
	[Categories].[modified_date],
	[Categories].[time_stamp]
FROM
	[#tmpTable]
	INNER JOIN [Categories] ON #tmpTable.[categoryid] = [CATEGORIES].[categoryid]
ORDER BY
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'CategoryName' THEN [Categories].[CategoryName] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'CategoryName' THEN [Categories].[CategoryName] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'CategoryID' THEN [Categories].[CategoryID] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'CategoryID' THEN [Categories].[CategoryID] END END

DROP TABLE #tmpTable

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_CategorySelectBySearchAnd]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_CategorySelectBySearchAnd]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_CategorySelectBySearchAnd]
(
	@CategoryName NVarChar(15) = null, 
	@CategoryID Int = null, 
	@paging_PageIndex int = -1, -- page number selected by the user
	@paging_RecordsperPage int = -1, -- number of items on the page
	@paging_OrderByColumn varchar(100) = '', -- name of column to order things by
	@paging_Ascending bit = 1, -- order column ascending or descending
	@paging_Count int out -- number of items in the collection
)
AS

CREATE TABLE #tmpTable 
(
	[CategoryID] Int
)

DECLARE @total__ivqatedr int
DECLARE @orderByColumnIndex int
-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@paging_RecordsperPage * @paging_PageIndex)
IF (@total__ivqatedr <> 0) AND (@paging_PageIndex <> -1)
BEGIN
	SET ROWCOUNT @total__ivqatedr
END
INSERT INTO #tmpTable
(
	[categoryid]
)
SELECT
	[Categories].[categoryid]
FROM
[Categories]
WHERE
((@CategoryName is null) OR ([Categories].[CategoryName] LIKE @CategoryName)) AND
((@CategoryID is null) OR ([Categories].[CategoryID] = @CategoryID))
ORDER BY
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'CategoryName' THEN [Categories].[CategoryName] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'CategoryName' THEN [Categories].[CategoryName] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'CategoryID' THEN [Categories].[CategoryID] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'CategoryID' THEN [Categories].[CategoryID] END END

	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Categories].[created_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Categories].[created_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Categories].[created_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Categories].[created_date] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Categories].[modified_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Categories].[modified_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Categories].[modified_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Categories].[modified_date] END END
-- set @paging_Count based on the rows moved in the previous statement
SET ROWCOUNT 0
SET @paging_Count = (
SELECT count(*)
FROM
[Categories]
WHERE
((@CategoryName is null) OR ([Categories].[CategoryName] LIKE @CategoryName)) AND
((@CategoryID is null) OR ([Categories].[CategoryID] = @CategoryID))
)

-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@paging_RecordsperPage * @paging_PageIndex) - @paging_RecordsperPage
IF (@total__ivqatedr <> 0) AND (@paging_PageIndex <> -1)
BEGIN
	SET ROWCOUNT @total__ivqatedr
	DELETE FROM #tmpTable
END

-- return the number of rows requested as the page size
IF (@paging_PageIndex <> -1)
BEGIN
SET ROWCOUNT @paging_RecordsperPage
END
SELECT
	[Categories].[categoryname],
	[Categories].[categoryid],
	[Categories].[picture],
	[Categories].[description],
	[Categories].[created_by],
	[Categories].[created_date],
	[Categories].[modified_by],
	[Categories].[modified_date],
	[Categories].[time_stamp]
FROM
	[#tmpTable]
	INNER JOIN [Categories] ON #tmpTable.[categoryid] = [CATEGORIES].[categoryid]
ORDER BY
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'CategoryName' THEN [Categories].[CategoryName] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'CategoryName' THEN [Categories].[CategoryName] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'CategoryID' THEN [Categories].[CategoryID] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'CategoryID' THEN [Categories].[CategoryID] END END

	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Categories].[created_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Categories].[created_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Categories].[created_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Categories].[created_date] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Categories].[modified_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Categories].[modified_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Categories].[modified_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Categories].[modified_date] END END
DROP TABLE #tmpTable

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_CategoryUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_CategoryUpdate]
GO


SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_CategoryUpdate]
(
	@CategoryName NVarChar(15),
	@Picture Image,
	@Description NText,
	@modified_by varchar (50),
	@modified_date datetime = null,
	@Original_CategoryID Int,
	@Original_time_stamp timestamp

)
AS

IF (@modified_date IS NULL)
SET @modified_date = GetDate();

SET NOCOUNT OFF;
UPDATE 
[Categories] 
SET
[CategoryName] = @CategoryName,
[Description] = @Description,
[Picture] = @Picture,
[modified_by] = @modified_by,
[modified_date] = @modified_date

WHERE
	[Categories].[CategoryID] = @Original_CategoryID AND
	[Categories].[time_stamp] = @Original_time_stamp


SELECT
	[Categories].[categoryname],
	[Categories].[categoryid],
	[Categories].[picture],
	[Categories].[description],
	[Categories].[created_by],
	[Categories].[created_date],
	[Categories].[modified_by],
	[Categories].[modified_date],
	[Categories].[time_stamp]
FROM 
[Categories]
WHERE
	[Categories].[CategoryID] = @Original_CategoryID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_CategorySelectByCreatedDateRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_CategorySelectByCreatedDateRange]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_CategorySelectByCreatedDateRange]
(
	@start_date datetime,
	@end_date datetime
)
AS

SET NOCOUNT ON;

SELECT
		[Categories].[categoryname],
	[Categories].[categoryid],
	[Categories].[picture],
	[Categories].[description],
	[Categories].[created_by],
	[Categories].[created_date],
	[Categories].[modified_by],
	[Categories].[modified_date],
	[Categories].[time_stamp]

FROM
[Categories]
WHERE
((([Categories].[created_date] IS NULL) AND (@start_date IS NULL)) OR (@start_date <= [Categories].[created_date])) AND 
((([Categories].[created_date] IS NULL) AND (@end_date IS NULL)) OR (@end_date >= [Categories].[created_date]))
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_CategorySelectByModifiedDateRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_CategorySelectByModifiedDateRange]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_CategorySelectByModifiedDateRange]
(
	@start_date datetime,
	@end_date datetime
)
AS

SET NOCOUNT ON;

SELECT
		[Categories].[categoryname],
	[Categories].[categoryid],
	[Categories].[picture],
	[Categories].[description],
	[Categories].[created_by],
	[Categories].[created_date],
	[Categories].[modified_by],
	[Categories].[modified_date],
	[Categories].[time_stamp]

FROM
[Categories]
WHERE
((([Categories].[modified_date] IS NULL) AND (@start_date IS NULL)) OR (@start_date <= [Categories].[modified_date])) AND 
((([Categories].[modified_date] IS NULL) AND (@end_date IS NULL)) OR (@end_date >= [Categories].[modified_date]))
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_CategorySelectBySearchOr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_CategorySelectBySearchOr]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_CategorySelectBySearchOr]
(
	@CategoryName NVarChar(15) = null, 
	@CategoryID Int = null, 
	@paging_PageIndex int = -1, -- page number selected by the user
	@paging_RecordsperPage int = -1, -- number of items on the page
	@paging_OrderByColumn varchar(100) = '', -- name of column to order things by
	@paging_Ascending bit = 1, -- order column ascending or descending
	@paging_Count int out -- number of items in the collection
)
AS

CREATE TABLE #tmpTable 
(
	[CategoryID] Int
)

DECLARE @total__ivqatedr int
DECLARE @orderByColumnIndex int
-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@paging_RecordsperPage * @paging_PageIndex)
IF (@total__ivqatedr <> 0) AND (@paging_PageIndex <> -1)
BEGIN
	SET ROWCOUNT @total__ivqatedr
END
INSERT INTO #tmpTable
(
	[categoryid]
)
SELECT
	[Categories].[categoryid]
FROM
[Categories]
WHERE
((@CategoryName is null) OR ([Categories].[CategoryName] LIKE @CategoryName)) OR
((@CategoryID is null) OR ([Categories].[CategoryID] = @CategoryID))
ORDER BY
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'CategoryName' THEN [Categories].[CategoryName] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'CategoryName' THEN [Categories].[CategoryName] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'CategoryID' THEN [Categories].[CategoryID] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'CategoryID' THEN [Categories].[CategoryID] END END

	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Categories].[created_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Categories].[created_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Categories].[created_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Categories].[created_date] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Categories].[modified_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Categories].[modified_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Categories].[modified_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Categories].[modified_date] END END
-- set @paging_Count based on the rows moved in the previous statement
SET ROWCOUNT 0
SET @paging_Count = (
SELECT count(*)
FROM
[Categories]
WHERE
((@CategoryName is null) OR ([Categories].[CategoryName] LIKE @CategoryName)) OR
((@CategoryID is null) OR ([Categories].[CategoryID] = @CategoryID))
)

-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@paging_RecordsperPage * @paging_PageIndex) - @paging_RecordsperPage
IF (@total__ivqatedr <> 0) AND (@paging_PageIndex <> -1)
BEGIN
	SET ROWCOUNT @total__ivqatedr
	DELETE FROM #tmpTable
END

-- return the number of rows requested as the page size
IF (@paging_PageIndex <> -1)
BEGIN
SET ROWCOUNT @paging_RecordsperPage
END
SELECT
	[Categories].[categoryname],
	[Categories].[categoryid],
	[Categories].[picture],
	[Categories].[description],
	[Categories].[created_by],
	[Categories].[created_date],
	[Categories].[modified_by],
	[Categories].[modified_date],
	[Categories].[time_stamp]
FROM
	[#tmpTable]
	INNER JOIN [Categories] ON #tmpTable.[categoryid] = [CATEGORIES].[categoryid]
ORDER BY
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'CategoryName' THEN [Categories].[CategoryName] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'CategoryName' THEN [Categories].[CategoryName] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'CategoryID' THEN [Categories].[CategoryID] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'CategoryID' THEN [Categories].[CategoryID] END END

	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Categories].[created_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Categories].[created_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Categories].[created_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Categories].[created_date] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Categories].[modified_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Categories].[modified_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Categories].[modified_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Categories].[modified_date] END END
DROP TABLE #tmpTable

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_CategorySelect]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_CategorySelect]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_CategorySelect]
AS

SET NOCOUNT ON;

SELECT
		[Categories].[categoryname],
	[Categories].[categoryid],
	[Categories].[picture],
	[Categories].[description],
	[Categories].[created_by],
	[Categories].[created_date],
	[Categories].[modified_by],
	[Categories].[modified_date],
	[Categories].[time_stamp]

FROM 
[Categories]
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

